package metrics_sql

const (
	K8sContainerCpuUsageV2 = `
guid = "%v"
container = /^(%v)$/

from(bucket: "data")
  |> range(start: %v, stop: %v)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["name"] == "container_cpu_used_cores")
  |> filter(fn: (r) => r["application_guid"] == guid)
  |> filter(fn: (r) => r["container"] =~ container)
`
	K8sContainerCpuUsagelastV2 = `
guid = "%v"
container = /^(%v)$/

from(bucket: "data")
  |> range(start: %v, stop: %v)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["name"] == "container_cpu_used_cores")
  |> filter(fn: (r) => r["application_guid"] == guid)
  |> filter(fn: (r) => r["container"] =~ container)
  |> last()
`
	GluenetsContainerCpuUsageV2 = `
containerRegex = /%v_(%v)+/

query = (start=%v,stop=%v,size=%f) => {
  return from(bucket: "data")
  |> range(start: start, stop: stop)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "container_cpu_usage_seconds_total")
  |> filter(fn: (r) => r["name"] =~ containerRegex)
  |> difference()
  |> group(columns:["_time"])
  |> sum(column: "_value")
  |> window(every: inf)
  |> map(fn: (r) => ({_field:"cpu_usage",_value:r._value  / 15.0  ,_time:r._time,instance:service,limit: 0.0}))
}

query()
`
	GluenetsContainerCpuUsagelastV2 = `
containerRegex = /%v_(%v)+/

query = (start=%v,stop=%v,size=%v) => {
  return from(bucket: "data")
  |> range(start: start, stop: stop)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "container_cpu_usage_seconds_total")
  |> filter(fn: (r) => r["label"] =~ containerRegex)
  |> difference()
  |> last()
  |> group(columns:["_time"])
  |> sum(column: "_value")
  |> window(every: inf)
  |> map(fn: (r) => ({_field:"cpu_usage",_value:r._value / 15.0  ,_time:r._time,instance:service,limit: 0.0}))
}

query()
`
)
